import { NoticeType } from 'antd/es/message/interface'
import { message, modal } from '../components/AntdTheme/AntdTheme';


// const [messageApi] = message.useMessage();



/**
 * 提示消息，依赖 ElmentUI
 */
export default class MsgBox {

	private static title = '系统提示';

	public static alert(content: string, title = this.title, confirmButtonText = '确定'): Promise<true> {
		return new Promise((resolve) => {
			modal.info({
				title,
				content,
				okText: confirmButtonText,
				keyboard: false, // 是否支持键盘 esc 关闭
				closable: false, // 是否显示右上角的关闭按钮
				centered: false, // 垂直居中展示 Modal
				onOk() {
					resolve(true);
				}
			});
		});
	}

	public static confirm = (
		content: string,
		title = this.title,
		confirmButtonText = '确定',
		cancelButtonText = '取消'
	): Promise<boolean> => {
		return new Promise((resolve) => {
			modal.confirm({
				title,
				content,
				okText: confirmButtonText,
				cancelText: cancelButtonText,
				keyboard: false, // 是否支持键盘 esc 关闭
				closable: false, // 是否显示右上角的关闭按钮
				centered: false, // 垂直居中展示 Modal
				onOk() {
					resolve(true);
				},
				onCancel() {
					resolve(false);
				}
			});
		});
	}

	public static toast = (content: string, type: NoticeType = 'info', duration = 3, key = ''): Promise<true> => {

		return new Promise((resolve) => {
			message.open({
				content,
				duration,
				type,
				key,
				onClose() {
					resolve(true);
				}
			})
		});
	}

	public static loading = (content: string | number = '数据提交中...请稍后') => {
		this.closeLoading();
		message.open({
			type: 'loading',
			key: 'loading',
			content,
			duration: 0,
		});
	}

	public static closeLoading = () => {
		message.destroy();
	}

}
